/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gym.manager.interfaz;

import com.gym.manager.mundo.Rutina;
import java.util.Calendar;
import java.util.TimeZone;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;

/**
 *
 * @author Sergio
 */
public class FormaAgregarRutina extends Form implements CommandListener {

    private MIDletGymManager principal;
    private DateField fechaInicio;
    private DateField fechaFin;
    private Command agregarRutina;
    private Calendar cal = Calendar.getInstance();

    /**
    Constructor.
     */
    public FormaAgregarRutina(MIDletGymManager interfaz) {
        super("Add workout");
        setCommandListener(this);

        principal = interfaz;

        agregarRutina = new Command("Add", Command.SCREEN, 0);
        addCommand(agregarRutina);

        fechaInicio = new DateField("Start date", DateField.DATE, TimeZone.getDefault());
        fechaFin = new DateField("End date", DateField.DATE, TimeZone.getDefault());

        fechaInicio.setDate(cal.getTime());
        append(fechaInicio);
        fechaFin.setDate(cal.getTime());
        append(fechaFin);


    }

    public void commandAction(Command c, Displayable d) {
        if (c == agregarRutina) {
            Rutina rut = principal.crearRutina(fechaInicio.getDate(), fechaFin.getDate());
            principal.mostrarFormaEditarRutina(new Alert("Info", "Workout added!", null, AlertType.INFO), rut);
        }

    }
}
